﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace TomAndJerryMidnightSnack
{

    class ScoreScreen : GameScreen
    {

        Texture2D backgroundTexture;
        Texture2D NextTexture;
        SpriteFont font;
        Vector2 NextPosition;
        /// <summary>
        /// Constructor.
        /// </summary>
        public ScoreScreen()
            : base()
        {
            //sound effect for game
            //AudioManager.PushMusic("LoseTheme",false);
            this.Exiting += new EventHandler(HomeScreen_Exiting);
        }


        void HomeScreen_Exiting(object sender, EventArgs e)
        {
            //stop music
            //AudioManager.PopMusic();
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

            backgroundTexture = content.Load<Texture2D>(@"ScoreBg");
            NextTexture = content.Load<Texture2D>(@"Buttons\next");
            font = content.Load<SpriteFont>(@"Fonts\gameFont");
            NextPosition = new Vector2(100, 480);
        }

        /// <summary>
        /// UnloadContent
        /// </summary>

        public override void UnloadContent()
        {
            base.UnloadContent();
        }

        /// <summary>
        /// Handles user input.
        /// </summary>
        public override void HandleInput()
        {
            if (InputManager.IsButtonClicked(new Rectangle(
                (int)NextPosition.X - NextTexture.Height, (int)NextPosition.Y,
                (int)(NextTexture.Height),
                (int)(NextTexture.Width))))
            {
                GameScreen screen = new PlayScreen();
                ExitScreen();
                ScreenManager.AddScreen(screen);
                ScreenManager.RemoveScreen(this);
            }

            base.HandleInput();
        }

        /// <summary>
        /// Updates the menu.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }


        /// <summary>
        /// Draws the menu.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            ScreenManager.GraphicsDevice.SetRenderTarget(ScreenManager.FinalImageTarget);
            ScreenManager.GraphicsDevice.Clear(Color.CornflowerBlue);

            // we will do all of our drawing here
            ScreenManager.GraphicsDevice.SetRenderTarget(null);

            spriteBatch.Begin();
            spriteBatch.Draw(backgroundTexture, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.Draw(NextTexture, NextPosition, null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.DrawString(font, "Score: " + ScreenManager.Score, new Vector2(350, 100), Color.White, MathHelper.PiOver2, Vector2.Zero, 3f, SpriteEffects.None, 0f);
            //spriteBatch.DrawString(font, "Level: " + ScreenManager.Level, new Vector2(300, 100), Color.White, MathHelper.PiOver2, Vector2.Zero, 3f, SpriteEffects.None, 0f);
            spriteBatch.End();
        }
    }
}
